<template>
  <div>
    <h3>本企业目前收到的简历投递</h3>
<!--    {{this.tableData}}-->
    <el-table :data="tableData" stripe border class="delivery_table">
      <el-table-column prop="deliveryId" label="投递编号" width="80"></el-table-column>
      <el-table-column prop="deliverySeeker" label="求职者编号" width="120"></el-table-column>
      <el-table-column prop="seekerName" label="求职者" width="170"></el-table-column>
      <el-table-column prop="deliveryOccupation" label="职位编号" width="80"></el-table-column>
      <el-table-column prop="occupationName" label="职位" width="200"></el-table-column>
      <el-table-column prop="enterpriseName" label="企业名称" width="500"></el-table-column>
      <el-table-column fixed="right" label="操作" width="200">
        <template slot-scope="scope">
          <el-button :plain="true" @click="openDialog(scope.row)" type="primary" icon="el-icon-s-custom">处理面试</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog :visible.sync="dialogVisible" title="添加面试安排">
    <el-form :model="form" ref="form" label-width="120px" class="demo-ruleForm">
      <el-form-item label="面试地点" :rules="[{ required: true, message: '请输入面试地点', trigger: 'blur' }]">
        <el-input v-model="form.interviewLocation" />
      </el-form-item>
      <el-form-item label="面试日期" :rules="[{ required: true, message: '请选择面试日期', trigger: 'change' }]">
        <el-date-picker v-model="form.interviewDate" type="date" value-format="yyyy-MM-dd" placeholder="选择日期" :picker-options="pickerOptions" />
      </el-form-item>
      <el-form-item label="面试时间" :rules="[{ required: true, message: '请选择面试时间', trigger: 'change' }]">
        <el-time-picker v-model="form.interviewTime" value-format="HH:mm:ss" placeholder="选择时间" />
      </el-form-item>
      <el-form-item label="职位" :rules="[{ required: true, message: '请输入职位', trigger: 'blur' }]">
        <el-input v-model="form.interviewOccupation" readonly/>
      </el-form-item>
      <el-form-item label="公司" :rules="[{ required: true, message: '请输入公司名称', trigger: 'blur' }]">
        <el-input v-model="form.interviewEnterprise" readonly/>
      </el-form-item>
      <el-form-item label="求职者" :rules="[{ required: true, message: '请输入求职者姓名', trigger: 'blur' }]">
        <el-input v-model="form.interviewSeeker" readonly/>
      </el-form-item>
<!--      <el-form-item>-->
<!--        <el-button type="primary" @click="submitInterview">提交面试安排</el-button>-->
<!--      </el-form-item>-->
    </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="submitInterview">保存</el-button>
      </div>
    <el-alert v-if="message" :title="message" type="success" center />
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData:[{
        deliveryId: '',
        deliveryOccupation: '',
        deliverySeeker: '',
        seekerName: '',
        occupationName: '',
        enterpriseName: ''
      }],
      form: {
        interviewLocation: '',
        interviewDate: '',
        interviewTime: '',
        interviewOccupation: '',
        interviewEnterprise: '',
        interviewSeeker: ''
      },
      dialogVisible:false,
      message: '',
      deliveryData:{
        interviewEnterprise:''
      },
      pickerOptions: {
        disabledDate(v) {
          return v.getTime() < new Date().getTime() - 86400000; // 禁用过去的日期，包括今天
        }
      }
    };
  },
  methods: {

    fetchDelivery(){
      this.$axios.post('/delivery/selectByEnterpriseId',this.deliveryData).then((resp) => {
        this.tableData = resp.data
      });
    },

    openDialog(delivery){
      this.form.interviewSeeker = delivery.deliverySeeker;
      this.form.interviewOccupation = delivery.deliveryOccupation;
      this.form.interviewEnterprise = this.deliveryData.interviewEnterprise;
      this.dialogVisible = true;
    },

    submitInterview() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$axios.post('/interview/insertInterview', this.form).then((resp) => {
            if (resp.data.code > -1) {
              this.$message({
                showClose: true,
                message: '新增面试信息成功',
                type: 'success'
              });
              // 重置表单
              this.$refs.form.resetFields();
              this.dialogVisible = false;
              this.fetchDelivery()
            } else {
              this.$message({
                showClose: true,
                message: '新增面试信息失败',
                type: 'error'
              });
            }
          });
        } else {
          this.$message({
            showClose: true,
            message: '请完整填写表单',
            type: 'warning'
          });
          return false;
        }
      });
    }
  },

  mounted() {
    this.fetchDelivery();
  },

  created() {
    this.deliveryData.interviewEnterprise = this.$store.state.id
  }
}
</script>

<style scoped>
.demo-ruleForm {
  max-width: 600px;
  margin: 0 auto;
}
</style>
